package alg20250316;

public class Text {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        //1 创建表
        int[] dp = new int[n + 1];
        //2 初始化

        //3 填表
        for(int i = 1; i <= n; i++){
            dp[i] = Math.max(nums[i - 1], dp[i - 1] + nums[i - 1]);
        }
        int max = dp[1];
        for (int i = 2; i <= n; i++) {
            if(dp[i] > max){
                max = dp[i];
            }
        }
        //4 返回值
        return max;
    }
}
